package org.sws.domain.activity.service.quota.policy;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.sws.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import org.sws.types.enums.ResponseCode;
import org.sws.types.exception.AppException;

import java.util.Map;

/**
 * @Author sws
 * @Date 2025/4/2 16:28
 * @description: 抽奖额度兑换策略上下文
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TradePolicyContext {
    private final Map<String,ITradePolicy> tradePolicyMap;

    public void rechargeTrade(String orderTradeType, CreateQuotaOrderAggregate createQuotaOrderAggregate){
        ITradePolicy tradePolicy = tradePolicyMap.get(orderTradeType);
        if(null == tradePolicy){
            log.warn("请配置或检查抽奖额度交易策略实现类.{}",orderTradeType);
            throw new AppException(ResponseCode.UN_ERROR.getCode(),ResponseCode.UN_ERROR.getInfo());
        }
        tradePolicy.trade(createQuotaOrderAggregate);
    }
}
